﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using OSVDB_Logic;
using OSVDB_TrayApp.Properties;

namespace OSVDB_TrayApp
{
    /// <summary>
    /// Interaction logic for Stats.xaml
    /// </summary>
    public partial class Stats : Window
    {
        Settings MySettings;

        public Stats()
        {
            MySettings = Settings.Default;

            InitializeComponent();

            try
            {
                OSVDBStats stats = new OSVDBStats(MySettings.StatsUrl);

                Dictionary<string, string> stat = stats.Stats;

                Array arr = stat.ToArray();

                lb_vulncount.Content = "Total Vulnerabilites in Database: " + ((KeyValuePair<string, string>)arr.GetValue(0)).Value;
                lb_vend1.Content = "1. " + ((KeyValuePair<string, string>)arr.GetValue(1)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(1)).Value;
                lb_vend2.Content = "2. " + ((KeyValuePair<string, string>)arr.GetValue(2)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(2)).Value;
                lb_vend3.Content = "3. " + ((KeyValuePair<string, string>)arr.GetValue(3)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(3)).Value;
                lb_vend4.Content = "4. " + ((KeyValuePair<string, string>)arr.GetValue(4)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(4)).Value;
                lb_vend5.Content = "5. " + ((KeyValuePair<string, string>)arr.GetValue(5)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(5)).Value;
                lb_vend6.Content = "6. " + ((KeyValuePair<string, string>)arr.GetValue(6)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(6)).Value;
                lb_vend7.Content = "7. " + ((KeyValuePair<string, string>)arr.GetValue(7)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(7)).Value;
                lb_vend8.Content = "8. " + ((KeyValuePair<string, string>)arr.GetValue(8)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(8)).Value;
                lb_vend9.Content = "9. " + ((KeyValuePair<string, string>)arr.GetValue(9)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(9)).Value;
                lb_vend10.Content = "10. " + ((KeyValuePair<string, string>)arr.GetValue(10)).Key + ": " + ((KeyValuePair<string, string>)arr.GetValue(10)).Value;

                this.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show("The information you requested is temporarily not available.\nPlease try again later", "Unavailable", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
    }
}
